import java.util.Deque;
import java.util.LinkedList;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class MyStack {

    Deque<Integer> deque1; // 模拟栈
    Deque<Integer> deque2; // 辅助队列

    public MyStack() {
        deque1 = new LinkedList<>();
        deque2 = new LinkedList<>();
    }

    // 将元素 x 压入栈顶
    public void push(int x) {
        deque2.offer(x);
        // 判断deque1是否为空，不为空则把deque1的元素依次出队到deque2
        while (!deque1.isEmpty()){
            deque2.offer(deque1.poll());
        }
        // 交换deque1和deque2
        Deque<Integer> temp = deque1;
        deque1 = deque2;
        deque2 = temp;
    }
    // 移除并返回栈顶元素
    public int pop() {
        return deque1.poll();
    }

    public int top() {
        return deque1.peek();
    }

    public boolean empty() {
        return deque1.isEmpty();
    }
}
